﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using RED_NET_Core.BLL;
using RED_NET_Core.Entity;
namespace RED_NET.ContentPage.User
{
    public partial class MainPage : System.Web.UI.Page
    {
        private static int uid=-1, visitId;

        protected void Init()
        {
            Session["PageName"] = "MainPage";
            if(Session["USER_ID"]!=null)
            uid = (int)Session["USER_ID"];
            if(Request.QueryString["VISIT_ID"]!=null)
            visitId = Int32.Parse(Request.QueryString["VISIT_ID"]);
            else
                Response.Redirect("~/ContentPage/Error/PageError.aspx");
            Album_PhotoBLL _photo = new Album_PhotoBLL();
            DataTable _dt = new DataTable();
            try
            {
               _dt = _photo.GetPhotoList(visitId, 5); 
                DataList_ShowNewPhoto.DataSource = _dt;
            DataList_ShowNewPhoto.DataBind();
            }
            catch (Exception ex)
            {
                Response.Redirect("~/ContentPage/Error/PageError.aspx");
            }
            if (_dt.Rows.Count == 0)
            {
                Label_NULL_Photo.Visible = true;
            }
            else
                Label_NULL_Photo.Visible =false;
            HyperLink_Message.NavigateUrl=HyperLink_Message.NavigateUrl+ visitId.ToString();
            HyperLink_MyDaily.NavigateUrl=HyperLink_MyDaily.NavigateUrl+visitId.ToString();
            DataTable _mdt = News_BLL.ShowMessageList(visitId);
          int i;
            for (i = 5; i < _mdt.Rows.Count; i++)
            {
                _mdt.Rows[i].Delete();
            }
            DataList_Message.DataSource = _mdt;
            DataList_Message.DataKeyField = "_Id";
            DataList_Message.DataBind();
            if (_mdt.Rows.Count == 0)
            {
                Label_NULL_Message.Visible = true;
            }
            else
                Label_NULL_Message.Visible = false;
            DataTable _ddt = News_BLL.ShowDailyList(visitId, 0);
            if (_ddt.Rows.Count == 0)
            {
                Label_NULL_Daily.Visible = true;
            }
            else
                Label_NULL_Daily.Visible = false;
            for (i = 5; i < _ddt.Rows.Count; i++)
            {
                _ddt.Rows[i].Delete();
            }
            DataList_MyDaily.DataSource = _ddt;
            DataList_MyDaily.DataKeyField = "_Id";
            DataList_MyDaily.DataBind();
            HyperLink_Message.NavigateUrl = "~/ContentPage/News/MessageBoard.aspx?VISIT_ID=" + visitId.ToString();
            HyperLink_MyDaily.NavigateUrl ="~/ContentPage/News/DailyList.aspx?VISIT_ID="+ visitId.ToString();
            HyperLink_MyPhoto.NavigateUrl = "~/ContentPage/Album.aspx?VISIT_ID=" + visitId.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
           
            Init();
        }
      

        protected void MyDaily_Reply_Click(object source, DataListCommandEventArgs e)
        {
           
            int _id = (int) DataList_MyDaily.DataKeys[e.Item.ItemIndex];
            Response.Redirect("~/ContentPage/News/ShowDaily.aspx?_Id=" + _id.ToString() + "&VISIT_ID=" + visitId.ToString());
        }
        protected void MyMessage_Reply_Click(object source, DataListCommandEventArgs e)
        {

            int _id = (int)DataList_Message.DataKeys[e.Item.ItemIndex];
            Response.Redirect("~/ContentPage/News/ShowDaily.aspx?_Id=" + _id.ToString() + "&_IsMessage=1&VISIT_ID=" + visitId.ToString());
        }
       

    }
}
